package com.example.pipeline.config;

import com.example.pipeline.base.BusinessCode;
import com.example.pipeline.base.ProcessTemplate;
import com.example.pipeline.service.ProcessComponent;
import com.example.pipeline.service.impl.BuildeLoanInfoAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author code威
 * @version 1.0
 * @description: 责任链配置
 * @date 2022/9/18 17:09
 */
@Configuration
public class PipelineConfig {

    @Autowired
    private BuildeLoanInfoAction buildeLoanInfoAction;


    @Bean("commonSendTemplate")
    public ProcessTemplate commonSendTemplate() {
        ProcessTemplate processTemplate = new ProcessTemplate();
        //流程顺序
        processTemplate.setProcessList(Arrays.asList(buildeLoanInfoAction));
        return processTemplate;
    }


    /**
     * pipeline流程控制器
     * 后续扩展则加BusinessCode和ProcessTemplate
     * @return
     */
    @Bean
    public ProcessComponent processComponent() {
        ProcessComponent processComponent = new ProcessComponent();
        Map<String, ProcessTemplate> templateConfig = new HashMap<>(1);
        templateConfig.put(BusinessCode.CREDIT_SCENES_SCAN.getCode(),commonSendTemplate());
        processComponent.setTemplateConfig(templateConfig);
        return processComponent;
    }
}
